import {useEffect, useState} from "react";

const UseSecondsCount = () => {
    const [seconds, setSeconds]  =  useState(35);
    const[timeout, _setTimeout]   =  useState();
    const TimerDown  =  ()  =>  {
        setSeconds((prev) => prev - 1);
    }
    const runTimer = ()   =>  {
        if (seconds === 0) return
        const time =  setTimeout(()=>{
            TimerDown();
        }, 1000);
        _setTimeout(time);
    }

    useEffect(()=>  {
        runTimer()
    }, [seconds]);

    return {seconds}
}

export default UseSecondsCount;